package net.wanho.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.SupplyDTO;
import net.wanho.po.Supply;
import net.wanho.service.SupplyService;
import net.wanho.mapper.SupplyMapper;
import net.wanho.vo.PageInfo;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【supply(供货商表)】的数据库操作Service实现
* @createDate 2025-04-28 11:41:58
*/
@Service
public class SupplyServiceImpl extends ServiceImpl<SupplyMapper, Supply>
    implements SupplyService{

    @Override
    public PageInfo<Supply> pageList(int pageNum, int pageSize, SupplyDTO supplyDTO) {
        Page<Supply> page = new Page<>(pageNum, pageSize);

        QueryWrapper<Supply> wrapper = new QueryWrapper<>();
        wrapper.like(!ObjectUtil.isEmpty(supplyDTO.getSupplyName()),"supply_name", supplyDTO.getSupplyName());
        wrapper.eq(!ObjectUtil.isEmpty(supplyDTO.getAddress()),"address", supplyDTO.getAddress());
        wrapper.eq(!ObjectUtil.isEmpty(supplyDTO.getContact()),"contact", supplyDTO.getContact());
        wrapper.eq(!ObjectUtil.isEmpty(supplyDTO.getPhone()),"phone", supplyDTO.getPhone());

        Page<Supply> p = this.baseMapper.selectByPage(page, wrapper);

        PageInfo<Supply> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getPages());
        pageInfo.setLimitIndex(page.offset());
        pageInfo.setResultList(p.getRecords());
        return pageInfo;
    }

    @Override
    public Boolean selectIdBySupplyName(String supplyNum) {
        Supply supply = this.baseMapper.selectOne(new QueryWrapper<Supply>().eq("supply_num", supplyNum));
        return supply == null;
    }
}




